/**
 * @author Anna-Katharina Wickert 
 * @author Yannic Remmet
 * @author Tobias Trabelsi
 * 
 * @version 
 * @since 27.07.2012
 *
 * @license Beer-Ware License (Revision 42)
 *
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * We wrote this file. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy us a beer in return.
 * ----------------------------------------------------------------------------
 */
package model;

import gui.MainFrame;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.swing.JOptionPane;

public class TreeItemFactory {
	String author= "";
	String defaultText = "";
	String defaultGroup = "";
	
	public TreeItemFactory() throws IOException {
		File f = new File(MainFrame.confFile.toString());

		if (f.exists()){
			BufferedReader r =  new BufferedReader(new FileReader(f));
			author = r.readLine();
			defaultText = r.readLine();
			defaultGroup = r.readLine();
			r.close();
		}
		else{
				PrintWriter w = new PrintWriter(f);
				author = JOptionPane.showInputDialog("Insert Author's Name");
				defaultText = JOptionPane.showInputDialog("Insert Default Name for ToDo's");
				defaultGroup = JOptionPane.showInputDialog("Insert Default Group Name");
				if (defaultText.equals("")){
					defaultText = "New ToDo";
				}
				if (defaultGroup.equals("")){
					defaultGroup = "New Group";
				}
				w.write(author+"\n");
				w.write(defaultText+"\n");
				w.write(defaultGroup+"\n");
				w.close();

		}
	}
	
	public TreeItem makeItem(){
		return new TreeItem(defaultText, null,0,new Date(),author,"",false);
	}
	public TreeGroup makeGroup(){
		return new TreeGroup(defaultGroup, null);
	}
}
